/**
 * @desc
 * @author  刘贺[of2220]
 * @company qianmi.com
 * @Date    2017/2/10
 */
"use strict";
import $http from 'webutil/ajax';
import Promise from 'webutil/promise';

export default class CateInfoApi {

    static getCategoryTree() {
        return new Promise((resolve, reject) => {
            $http.post('/relatedImgInfo/getCategoryTree', {}).then((res) => {
                resolve(res.data);
            }, (err) => {
                reject(err);
            });
        });
    }

    static createNewCate({id, name, pid}) {
        return new Promise((resolve, reject) => {
            $http.post('/relatedImgInfo/createNewCate', {id, name, pid}).then((res) => {
                resolve(res.data);
            }, (err) => {
                reject(err);
            });
        });
    }

    static getCateTreeAndImgByPid({id, pageNum, pageSize}) {
        return new Promise((resolve, reject) => {
            $http.post('/relatedImgInfo/getCateTreeAndImgByPid', {id, pageNum, pageSize}).then((res) => {
                resolve(res.data);
            }, (err) => {
                reject(err);
            });
        });
    }

    static updateCateName({id,name}){
        return new Promise((resolve, reject) => {
            $http.post('/relatedImgInfo/updateCateName',{id,name}).then((res)=>{
                res.result === 'ok' ? resolve(res.data) : reject(res.message)
            },(err)=>{
                reject(err);
            });
        });
    }

    static deleteCate({id}){
        return new Promise((resolve, reject) => {
            $http.post('/relatedImgInfo/deleteCate',{id} ).then((res)=>{
                res.result === 'ok' ? resolve(res.data) : reject(res.message)
            },(err)=>{
                reject(err);
            });
        });
    }

}



